#include <stdio.h>
#include "input_layer.h"
#include "maxpool_layer.h"
#include "network.h"

void add_maxpool_layer(network *net)
{
    int stride = 2;
    int size = 2;
    int padding = size-1;
    int batch,h,w,c;
    h = 7;
    w = 7;
    c = 1;
    batch=1;
    maxpool_layer layer = make_maxpool_layer(batch,h,w,c,size,stride,padding);
    net->layers[1] = layer;
}

void add_input_layer(network *net)
{
    int groups = 1;
    int batch,h,w,c;
    h = 7;
    w = 7;
    c = 1;
    batch=1;

    input_layer layer = make_input_layer(batch, h, w, c, groups);
    net->layers[0] = layer;
    net->inputs = h * w * c;
    if (net->workspace_size < layer.workspace_size) {
        net->workspace_size = layer.workspace_size;
    }
    int i,j,k;
    printf("input:\n");
    for (i = 0; i < layer.c; i++) {
        for (j = 0; j < layer.h; j++) {
            for (k = 0; k < layer.w; k++) {
                layer.output[(i * layer.w * layer.h) + j * layer.w + k] = (j + 1) * (k + 1) * 0.1;
                printf("%f ", layer.output[(i * layer.w * layer.h) + j * layer.w + k]);
            }
            printf("\n");
        }
        printf("\n");
    }
}


int main()
{
    int ret = 0;
    network *net;

    net = make_network(2);
    add_input_layer(net);

    add_maxpool_layer(net);
    forward_network(net);

    layer l = net->layers[1];
    int i,j,k;
    printf("output:\n");
    for (i = 0; i < l.out_c; i++) {
        for (j = 0; j < l.out_h; j++) {
            for (k = 0; k < l.out_w; k++) {
                printf("%f ", l.output[i * l.out_w * l.out_h + j * l.out_w + k]);
            }
            printf("\n");
        }
        printf("\n");
    }

    free_network(net);

    return ret;
}